package net.caixiaomi.info.app;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;

import net.caixiaomi.info.util.InitializeOptimizer;
import net.caixiaomi.info.util.InitializeUtil;

public class CXMInstrumentation extends Instrumentation {

    @Override
    public Activity newActivity(ClassLoader cl, String className, Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        if (InitializeOptimizer.isApplicationCreated()
                && (!InitializeOptimizer.isHighSDKInitialized()
                || !InitializeOptimizer.isLowSDKInitialized() && !InitializeUtil.isAppLauncher(intent))) {
            InitializeOptimizer.setApplicationCreated(false);
            intent.addCategory(InitializeUtil.INITIALIZE_CATEGORY);
            return (Activity) cl.loadClass(InitializeUtil.getLaunchClassName()).newInstance();
        }
        InitializeOptimizer.setApplicationCreated(false);
        return super.newActivity(cl, className, intent);
    }
}
